class PlayerController < ApplicationController

  def index
    @players = GAME_ENGINE.players
  end
  
  def new
    @error_message=params[:error_message]
  end
  
  def add
    player = Player.new sanatize(params[:player_name])
    begin
      GAME_ENGINE.add_player player
      session[:player_name]=player.name
      redirect_to :controller => "strategy", :action => "index"
    rescue PlayerExistsError
      redirect_to :action => "new", :error_message => $!.message
    end      
  end
  
  def sanatize player_name
    name=player_name.strip.downcase
    return name
  end
end
